package com.aspect;

import javax.servlet.*;
import java.io.IOException;

public class CharacterEncodingFilter implements Filter {

    @Override
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
        request.setCharacterEncoding("GBK");
        response.setCharacterEncoding("GBK");
        System.out.println("CharacterEncodingFilter执行前。。。。");
        //让请求继续走，如果不写程序到这里就被拦截停止了！
        chain.doFilter(request, response);
        System.out.println("CharacterEncodingFilter执行后。。。。");
    }

    @Override
    public void init(FilterConfig filterConfig) throws ServletException {
        System.out.println("CharacterEncodingFilter创建了");
    }

    @Override
    public void destroy() {
        System.out.println("CharacterEncodingFilter销毁了");
    }
}
